/////////////////////////////////////////////////////////////////////////////
// Name:        RemovePkgDialog.cpp
// Purpose:     
// Author:      yospaly
// Modified by: 
// Created:     14/01/2009 17:26:40
// RCS-ID:      
// Copyright:   Copyright (C) 2008, yospaly
// Licence:     
/////////////////////////////////////////////////////////////////////////////

// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
#pragma hdrstop
#endif

#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif

////@begin includes
////@end includes

#include "RemovePkgDialog.h"
#include "events.h"

////@begin XPM images
////@end XPM images


/*!
 * RemovePkgDialog type definition
 */

IMPLEMENT_DYNAMIC_CLASS( RemovePkgDialog, wxDialog )


/*!
 * RemovePkgDialog event table definition
 */

BEGIN_EVENT_TABLE( RemovePkgDialog, wxDialog )

////@begin RemovePkgDialog event table entries
////@end RemovePkgDialog event table entries

	EVT_COMMAND( ID_REMOVEPKG_DIALOG, wxEVT_PKG_REMOVE_BEGIN_EVENT, RemovePkgDialog::OnPkgRemoveBegin)
	EVT_COMMAND( ID_REMOVEPKG_DIALOG, wxEVT_PKG_REMOVING_EVENT, RemovePkgDialog::OnPkgRemoving)
	EVT_COMMAND( ID_REMOVEPKG_DIALOG, wxEVT_PKG_REMOVE_COMPLETED_EVENT, RemovePkgDialog::OnPkgRemoveCompleted)
	EVT_COMMAND( ID_REMOVEPKG_DIALOG, wxEVT_PKGS_REMOVE_BEGIN_EVENT, RemovePkgDialog::OnPkgsRemoveBegin)
	EVT_COMMAND( ID_REMOVEPKG_DIALOG, wxEVT_PKGS_REMOVE_COMPLETED_EVENT, RemovePkgDialog::OnPkgsRemoveCompleted)

END_EVENT_TABLE()


/*!
 * RemovePkgDialog constructors
 */

RemovePkgDialog::RemovePkgDialog()
{
    Init();
}

RemovePkgDialog::RemovePkgDialog( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
{
    Init();
    Create(parent, id, caption, pos, size, style);
}


/*!
 * RemovePkgDialog creator
 */

bool RemovePkgDialog::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
{
////@begin RemovePkgDialog creation
    SetExtraStyle(wxWS_EX_BLOCK_EVENTS);
    wxDialog::Create( parent, id, caption, pos, size, style );

    CreateControls();
    Centre();
////@end RemovePkgDialog creation
    return true;
}


/*!
 * RemovePkgDialog destructor
 */

RemovePkgDialog::~RemovePkgDialog()
{
////@begin RemovePkgDialog destruction
////@end RemovePkgDialog destruction
}


/*!
 * Member initialisation
 */

void RemovePkgDialog::Init()
{
////@begin RemovePkgDialog member initialisation
    p_remove_log_textctrl = NULL;
    p_remove_progress_gauge = NULL;
////@end RemovePkgDialog member initialisation
}


/*!
 * Control creation for RemovePkgDialog
 */

void RemovePkgDialog::CreateControls()
{    
////@begin RemovePkgDialog content construction
    RemovePkgDialog* itemDialog1 = this;

    wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
    itemDialog1->SetSizer(itemBoxSizer2);

    wxStaticText* itemStaticText3 = new wxStaticText( itemDialog1, wxID_STATIC, _("Following packages are marked for changing :"), wxDefaultPosition, wxDefaultSize, 0 );
    itemBoxSizer2->Add(itemStaticText3, 0, wxGROW|wxALL, 5);

    p_remove_log_textctrl = new wxTextCtrl( itemDialog1, ID_REMOVE_LOG_TEXTCTRL, _T(""), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxTE_READONLY|wxTE_RICH2|wxTE_AUTO_URL|wxHSCROLL );
    itemBoxSizer2->Add(p_remove_log_textctrl, 1, wxGROW|wxALL, 5);

    p_remove_progress_gauge = new wxGauge( itemDialog1, ID_REMOVE_PROGRESS_GAUGE, 100, wxDefaultPosition, wxDefaultSize, wxGA_HORIZONTAL );
    p_remove_progress_gauge->SetValue(0);
    itemBoxSizer2->Add(p_remove_progress_gauge, 0, wxGROW|wxALL, 5);

    wxStdDialogButtonSizer* itemStdDialogButtonSizer6 = new wxStdDialogButtonSizer;

    itemBoxSizer2->Add(itemStdDialogButtonSizer6, 0, wxALIGN_RIGHT|wxALL, 5);
    wxButton* itemButton7 = new wxButton( itemDialog1, wxID_OK, _("&OK"), wxDefaultPosition, wxDefaultSize, 0 );
    itemButton7->Enable(false);
    itemStdDialogButtonSizer6->AddButton(itemButton7);

    wxButton* itemButton8 = new wxButton( itemDialog1, wxID_CANCEL, _("&Cancel"), wxDefaultPosition, wxDefaultSize, 0 );
    itemStdDialogButtonSizer6->AddButton(itemButton8);

    itemStdDialogButtonSizer6->Realize();

////@end RemovePkgDialog content construction
    EventCenter::registerr(wxEVT_PKG_REMOVE_BEGIN_EVENT, this);
    EventCenter::registerr(wxEVT_PKG_REMOVING_EVENT, this);
    EventCenter::registerr(wxEVT_PKG_REMOVE_COMPLETED_EVENT, this);
    EventCenter::registerr(wxEVT_PKGS_REMOVE_BEGIN_EVENT, this);
    EventCenter::registerr(wxEVT_PKGS_REMOVE_COMPLETED_EVENT, this);
    
    // Keep original system font size
    wxFont font = p_remove_log_textctrl->GetFont();
    font.SetFaceName(_T("Courier New"));
    p_remove_log_textctrl->SetFont(font);
}


/*!
 * Should we show tooltips?
 */

bool RemovePkgDialog::ShowToolTips()
{
    return true;
}

/*!
 * Get bitmap resources
 */

wxBitmap RemovePkgDialog::GetBitmapResource( const wxString& name )
{
    // Bitmap retrieval
////@begin RemovePkgDialog bitmap retrieval
    wxUnusedVar(name);
    return wxNullBitmap;
////@end RemovePkgDialog bitmap retrieval
}

/*!
 * Get icon resources
 */

wxIcon RemovePkgDialog::GetIconResource( const wxString& name )
{
    // Icon retrieval
////@begin RemovePkgDialog icon retrieval
    wxUnusedVar(name);
    return wxNullIcon;
////@end RemovePkgDialog icon retrieval
}


void RemovePkgDialog::OnPkgRemoveBegin(wxCommandEvent &event) {
	p_remove_log_textctrl->AppendText(_T("==> Removing package : "));
	p_remove_log_textctrl->AppendText(event.GetString());
	p_remove_log_textctrl->AppendText(_T("\n"));
}
void RemovePkgDialog::OnPkgRemoving(wxCommandEvent &event) {
	p_remove_log_textctrl->AppendText(_T("    Delete "));
	p_remove_log_textctrl->AppendText(event.GetString());
	// p_remove_progress_gauge->Pulse();
	
	if ( -1==event.GetInt() ) {
		p_remove_log_textctrl->AppendText(_T(" ... OK\n"));
	} else {
		p_remove_log_textctrl->AppendText(_T(" ... False\n"));
	}
}
void RemovePkgDialog::OnPkgRemoveCompleted(wxCommandEvent &event) {
	p_remove_log_textctrl->AppendText(_T("\n---------------------------------\n\n"));
	p_remove_progress_gauge->SetValue(event.GetInt());
}
void RemovePkgDialog::OnPkgsRemoveBegin(wxCommandEvent &event) {
	p_remove_log_textctrl->AppendText(_T("Begin remove packages :\n\n"));
	p_remove_log_textctrl->AppendText(_T("---------------------------------\n\n"));
	p_remove_progress_gauge->SetRange(event.GetInt());
}
void RemovePkgDialog::OnPkgsRemoveCompleted(wxCommandEvent &event) {
	p_remove_log_textctrl->AppendText(_T("Packages removal have completed!"));
	p_remove_log_textctrl->AppendText(_T("\n"));
}

